/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rad.Java.MotelPlus.List;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import rad.Java.Common.Class.DefaultList;
import rad.Java.Common.Class.IList;
import rad.Java.Common.DB.GenerateSql;
import rad.Java.MotelPlus.Class.Stay;

/**
 *
 * @author rogerio
 */
public class Stays extends DefaultList implements IList{
    // <editor-fold defaultstate="collapsed" desc="Declaration of variables">
        private Stay s;
    // </editor-fold>
    
    public Stays(){
        s = new Stay();
        _gsql = new GenerateSql();
        _gsql.setTable("stay");
    }
    
    // <editor-fold defaultstate="collapsed" desc="Declaration of variables">
         public boolean fillList() {
            _gsql.prepare();
            _gsql.setCommandType(GenerateSql.CommandType.CMD_SELECT);
            _gsql.setValue("","*");

            return mountList();
        }

        public Stay get(int index){
            return (Stay) _items.get(index);
        }

        private boolean mountList(){
            try {
                ResultSet rs;
                if (!_gsql.execute(false)) {
                    return false;
                }
                clear();
                while (_gsql.next()) {
                    Stay stay = new Stay();
                    stay.get(_gsql.getResultSet());
                    _items.add(stay);
                }
                return true;
            }
            catch (SQLException ex) {
                Logger.getLogger(Stays.class.getName()).log(Level.SEVERE, null, ex);
                return false;
            }
        }
    // </editor-fold>
}
